from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def get_name(self):
        return "卓越传说"

    def game_alert(self):
        self.alert_close_by_file('./game/img/卓越传说')
        # while True:
        #     if self.alert_close('./game/img/卓越传说/alert.png'):
        #         continue
        #     if self.alert_close('./game/img/卓越传说/alert01.png'):
        #         continue
        #     break

    def handle_main(self):
        self.log_msg("等待进入游戏")
        self.game_alert()
        self.log_msg("点击开始游戏")
        self.img_click('./game/img/卓越传说/start.png')
        self.log_msg("等待进入游戏主界面")
        self.img_exit('./game/img/卓越传说/game_main.png', 100)
        self.log_msg("已进入游戏主界面")

        if self.not_prize_handle():
            return False

        self.game_alert()
        self.img_click_if_exists('点击boss', './game/img/卓越传说/play.png', './game/img/卓越传说/play01.png')
        self.log_msg("点击全民boss")
        self.img_click('./game/img/卓越传说/play01.png')
        # 可能会存在确定按钮

        while not self.img_exit('./game/img/卓越传说/play_wait.png'):
            self.log_msg("全民boss，不能进入，等待")
            self.d.sleep(3)
        self.log_msg("点击挑战全民boss")
        self.img_click('./game/img/卓越传说/play02.png')
        if self.img_exit('./game/img/卓越传说/play_alert.png', 3):
            self.log_msg("存在背包弹窗，点击确定")
            self.img_click('./game/img/卓越传说/play_alert.png')
            self.log_msg("点击挑战")
            self.img_click('./game/img/卓越传说/play02.png')

        while not self.img_exit('./game/img/卓越传说/win.png', 3):
            self.log_msg("挑战中，等待")
            self.d.sleep(10)
        self.log_msg("点击挑战完成")

        return True
